package com.dht.xiao.jianye.activity_work_clothes;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.dht.xiao.jianye.R;
import com.dht.xiao.jianye.base.BaseActivity;
import com.dht.xiao.jianye.utils.OpenManager;
import com.licheedev.myutils.LogPlus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.dlc.commonlibrary.utils.ToastUtil;

public class WorkTestActivity extends BaseActivity {
    @BindView(R.id.ed_num)
    EditText edNum;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_work_ceshi;
    }

    OpenManager openManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_work_ceshi);
        ButterKnife.bind(this);
        openManager = new OpenManager(this);
        openManager.setCallBack(new OpenManager.OpenCallBack() {
            @Override
            public void onReceiveData(String data, String command,long num, String status) {
                LogPlus.e("", "获取到数据结果--=" + data+"--command="+command);
                if (status.equals("00")&& command.equals("82")) {

                    ToastUtil.show(getActivity(), num + "号门已打开");

                } else if (status.equals("01")&& command.equals("83")){

                    ToastUtil.show(getActivity(), num + "号门已关闭");

                }
            }
            @Override
            public void onInit(Boolean data) {

            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        openManager.onDestroy();
    }


    @OnClick({R.id.btn_open, R.id.btn_query})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_open:
                String nums = edNum.getText().toString();
                if (nums.length() < 4 && !TextUtils.isEmpty(nums)) {
                    openManager.sendOpen(Integer.parseInt(nums));
                } else {
                    openManager.sendOpen(1);
                }
                break;
            case R.id.btn_query:
                String nums1 = edNum.getText().toString();
                if (nums1.length() < 4 && !TextUtils.isEmpty(nums1)) {
                    openManager.queryOpen(Integer.parseInt(nums1));
                } else {
                    openManager.queryOpen(1);
                }
                break;
        }
    }
}
